package test4.test4_17;

import test4.test4_17.interfaces.Area;
import test4.test4_17.interfaces.Volume;

/**
 * Cone
 */
public class Cone implements Area, Volume {
  private double r; // 底面半径
  private double h; // 圆锥的高

  Cone(double r, double h) {
    this.r = r;
    this.h = h;
  }

  /**
   * 计算表面积
   */
  public double area() {
    final double L = Math.sqrt(Math.pow(this.r, 2) + Math.pow(this.h, 2));
    return Math.PI * Math.pow(this.r, 2) + Math.PI * this.r * L;
  }

  /**
   * 计算体积
   */
  public double volume() {
    return 1.0 / 3.0 * Math.PI * Math.pow(this.r, 2) * this.h;
  }

  public static void main(String[] args) {
    Cone cone = new Cone(2, 3);
    System.out.println(cone.area());
    System.out.println(cone.volume());
  }
}